<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true"  label-width="68px">
<!--      <el-form-item label="用户ID" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入用户ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="部门ID" prop="deptId">
        <el-input
          v-model="queryParams.deptId"
          placeholder="请输入部门ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="姓名" prop="nickName">
        <el-input
          v-model="queryParams.nickName"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工号" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入工号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item v-show="showSearch" label="身份证号" prop="idNumber">
        <el-input
          v-model="queryParams.idNumber"
          placeholder="请输入身份证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item  v-show="showSearch" label="性别" prop="sex">
        <el-select v-model="queryParams.sex" placeholder="请选择性别" clearable>
          <el-option
            v-for="dict in dict.type.sys_user_sex"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item  v-show="showSearch" label="手机号" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item v-show="showSearch" label="职务" prop="post">
        <el-select v-model="queryParams.post" placeholder="请选择职务" clearable>
          <el-option
            v-for="dict in dict.type.yqg_post"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item  v-show="showSearch" label="部门" prop="department">
        <el-select v-model="queryParams.department" placeholder="请选择部门" clearable>
          <el-option
            v-for="dict in dict.type.yqg_department"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item v-show="showSearch" label="人员状态" prop="personnelStatus">
        <el-select v-model="queryParams.personnelStatus" placeholder="请选择人员状态" clearable>
          <el-option
            v-for="dict in dict.type.yqg_personnel_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

    </el-form>

    <el-form>
      <el-form-item style="text-align: right">
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['project:baseinfo:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['project:baseinfo:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
    </el-row>


    <el-table v-loading="loading" :data="baseinfoList" border @selection-change="handleSelectionChange" style="overflow-x: auto;">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column type="index" label="序号" width="55" :index="indexMethod" align="center"
                       v-if="columns[0].visible"></el-table-column>
<!--      <el-table-column label="用户ID" align="center" prop="userId" v-if="columns[1].visible"/>
      <el-table-column label="部门ID" align="center" prop="deptId" v-if="columns[2].visible"/>-->
      <el-table-column label="姓名" align="center" prop="nickName" v-if="columns[1].visible"/>
      <el-table-column label="工号" align="center" prop="userName" v-if="columns[2].visible"/>
      <el-table-column label="身份证号" align="center" prop="idNumber" v-if="columns[3].visible"/>
      <el-table-column label="性别" align="center" prop="sex" v-if="columns[4].visible">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.sex"/>
        </template>
      </el-table-column>
      <el-table-column label="手机号" align="center" prop="phone" v-if="columns[5].visible"/>
      <el-table-column label="职务" align="center" prop="post" v-if="columns[6].visible">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.yqg_post" :value="scope.row.post"/>
        </template>
      </el-table-column>
      <el-table-column label="部门" align="center" prop="department" v-if="columns[7].visible">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.yqg_department" :value="scope.row.department"/>
        </template>
      </el-table-column>
      <el-table-column label="人员状态" align="center" prop="personnelStatus" v-if="columns[8].visible">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.yqg_personnel_status" :value="scope.row.personnelStatus"/>
        </template>
      </el-table-column>
      <!--<el-table-column label="备注1" align="center" prop="note1" v-if="columns[11].visible"/>
     <el-table-column label="备注2" align="center" prop="note2" />
     <el-table-column label="备注3" align="center" prop="note3" />
     <el-table-column label="备注4" align="center" prop="note4" />
     <el-table-column label="备注5" align="center" prop="note5" />
     -->
      <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width" width="160">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>



    <!--    <el-table v-loading="loading" :data="baseinfoList" border @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center"/>
          <el-table-column type="index" label="序号" width="55"  align="center"
                           v-if="columns[0].visible" :index="getIndex"/>
          <el-table-column label="用户ID" align="center" prop="userId" v-if="columns[1].visible"/>
          <el-table-column label="部门ID" align="center" prop="deptId" v-if="columns[2].visible"/>
          <el-table-column label="用户昵称" align="center" prop="nickName" v-if="columns[3].visible">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.yh_gas_station" :value="scope.row.workPlace"/>
            </template>
          </el-table-column>
          <el-table-column label="性别" align="center" prop="sex" v-if="columns[4].visible">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.sex"/>
            </template>
          </el-table-column>
          <el-table-column label="工号" align="center" prop="userName" v-if="columns[5].visible"/>
          <el-table-column label="手机号" align="center" prop="phone" v-if="columns[6].visible"/>
          <el-table-column label="职位" align="center" prop="posts" v-if="columns[7].visible">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.yh_posts" :value="scope.row.posts"/>
            </template>
          </el-table-column>
          <el-table-column label="出生日期" align="center" prop="birth" width="180" v-if="columns[8].visible">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.birth, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="钢瓶瓶号" align="center" prop="cylinderNumber" v-if="columns[9].visible"/>
          <el-table-column label="应充介质" align="center" prop="gasMedia" v-if="columns[10].visible">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.yh_medium" :value="scope.row.gasMedia"/>
            </template>
          </el-table-column>
          <el-table-column label="钢瓶状态" align="center" prop="cylinderStatus" v-if="columns[11].visible">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.yh_cylinder_status" :value="scope.row.cylinderStatus"/>
            </template>
          </el-table-column>
          <el-table-column label="钢瓶重量" align="center" prop="weight" v-if="columns[12].visible"/>
          <el-table-column label="钢瓶容积" align="center" prop="volume" v-if="columns[13].visible"/>
          <el-table-column label="所属气站" align="center" prop="belongingGasStation" v-if="columns[14].visible">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.yh_gas_station" :value="scope.row.belongingGasStation"/>
            </template>
          </el-table-column>
          <el-table-column label="钢瓶生产日期" align="center" prop="manufactureDate" width="180"
                           v-if="columns[15].visible">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.manufactureDate, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="钢瓶报废日期" align="center" prop="scrapDate" width="180" v-if="columns[16].visible">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.scrapDate, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="气瓶检验时间" align="center" prop="inspectionTime" width="180" v-if="columns[17].visible">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.inspectionTime, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="下次检验时间" align="center" prop="nextInspectionTime" width="180" v-if="columns[18].visible">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.nextInspectionTime, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="气瓶制造单位" align="center" prop="manufacturingUnits" width="180"  v-if="columns[19].visible"/>
          <el-table-column label="充装气站" align="center" prop="fillingStation" width="180" v-if="columns[20].visible">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.yh_gas_station" :value="scope.row.fillingStation"/>
            </template>
          </el-table-column>
          <el-table-column label="充装介质" align="center" prop="fillingMedium" width="180" v-if="columns[21].visible">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.yh_medium" :value="scope.row.fillingMedium"/>
            </template>
          </el-table-column>
          <el-table-column label="充装时间" align="center" prop="note1" width="180" v-if="columns[22].visible">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.note1) }}</span>
            </template>
          </el-table-column>
          <el-table-column label="充装压力" align="center" prop="fillingPressure" v-if="columns[23].visible"/>
          <el-table-column label="充装温度" align="center" prop="fillingTemperature" v-if="columns[24].visible"/>
          <el-table-column label="有无异常情况" align="center" prop="transportVehicles" width="180" v-if="columns[25].visible">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.yh_anomalies" :value="scope.row.anomalies"/>
            </template>
          </el-table-column>
          <el-table-column label="运输车辆" align="center" prop="transportVehicles" v-if="columns[26].visible"/>

          &lt;!&ndash;      <el-table-column label="用户ID" align="center" prop="userId" />
                <el-table-column label="单位ID" align="center" prop="deptId" />&ndash;&gt;
          <el-table-column label="备注" align="center" prop="remark" v-if="columns[27].visible"/>
          <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width" width="160">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['zzy:filling:edit']"
              >修改</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['zzy:filling:remove']"
              >删除
              </el-button>
              <el-button
                size="mini"
                type="text"
                @click="handleView(scope.row)"
                v-hasPermi="['zzy:filling:xiangqing']"
              >详细</el-button>
            </template>
          </el-table-column>
        </el-table>-->


    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改人员基础信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="755px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px" :inline="true">
<!--        <el-form-item label="用户ID" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户ID" style="width: 240px"/>
        </el-form-item>
        <el-form-item label="部门ID" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入部门ID" style="width: 240px"/>
        </el-form-item>-->
        <el-form-item label="姓名" prop="nickName">
          <el-input v-model="form.nickName" placeholder="请输入姓名" style="width: 240px"/>
        </el-form-item>
        <el-form-item label="工号" prop="userName">
          <el-input v-model="form.userName" placeholder="请输入工号" style="width: 240px"/>
        </el-form-item>
        <el-form-item label="身份证号" prop="idNumber">
          <el-input v-model="form.idNumber" placeholder="请输入身份证号" style="width: 240px"/>
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <el-select v-model="form.sex" placeholder="请选择性别" style="width: 240px">
            <el-option
              v-for="dict in dict.type.sys_user_sex"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="手机号" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入手机号" style="width: 240px"/>
        </el-form-item>
        <el-form-item label="职务" prop="post">
          <el-select v-model="form.post" placeholder="请选择职务" style="width: 240px">
            <el-option
              v-for="dict in dict.type.yqg_post"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="部门" prop="department">
          <el-select v-model="form.department" placeholder="请选择部门" style="width: 240px">
            <el-option
              v-for="dict in dict.type.yqg_department"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="人员状态" prop="personnelStatus">
          <el-select v-model="form.personnelStatus" placeholder="请选择人员状态" style="width: 240px">
            <el-option
              v-for="dict in dict.type.yqg_personnel_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {listBaseinfo, getBaseinfo, delBaseinfo, addBaseinfo, updateBaseinfo} from "@/api/module/lyx/baseinfo";

export default {
  name: "Baseinfo",
  dicts: ['yqg_personnel_status', 'sys_user_sex', 'yqg_post', 'yqg_department'],
  data() {
    return {
      // 遮罩层
      columns: [
        {key: 0, label: `序号`, visible: true},
        /*{key: 1, label: `用户ID`, visible: true},
        {key: 2, label: `部门ID`, visible: true},*/
        {key: 1, label: `姓名`, visible: true},
        {key: 2, label: `工号`, visible: true},
        {key: 3, label: `身份证号`, visible: true},
        {key: 4, label: `性别`, visible: true},
        {key: 5, label: `手机号`, visible: true},
        {key: 6, label: `职务`, visible: true},
        {key: 7, label: `部门`, visible: false},
        {key: 8, label: `人员状态`, visible:false},
        /*{key: 11, label: `备注1`, visible: true},*/

      ],
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: false,
      // 总条数
      total: 0,
      // 人员基础信息表格数据
      baseinfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        deptId: null,
        nickName: null,
        userName: null,
        idNumber: null,
        sex: null,
        phone: null,
        post: null,
        department: null,
        personnelStatus: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getIndex(index) {
      return index + 1 + (this.queryParams.pageNum - 1) * this.queryParams.pageSize
    },
    /** 查询人员基础信息列表 */
    getList() {
      this.loading = true;
      listBaseinfo(this.queryParams).then(response => {
        this.baseinfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        ID: null,
        userId: null,
        deptId: null,
        nickName: null,
        userName: null,
        idNumber: null,
        sex: null,
        phone: null,
        post: null,
        department: null,
        personnelStatus: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加人员基础信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getBaseinfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改人员基础信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateBaseinfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBaseinfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除人员基础信息编号为"' + ids + '"的数据项？').then(function () {
        return delBaseinfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('project/baseinfo/export', {
        ...this.queryParams
      }, `baseinfo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
